<?php
/**
 *
 * @revision:   $Id: helper.php 1.0.0 2011-05-11 17:30:20 ALEXEY GORDEYEV IK $
 * @package	    Joomla!
 * @since       {SINCE}
 * @subpackage	AG 3D Carousel
 * @version     {PROJECTVERSION}
 * @desc        Image Carousel module based on ImageFlow object-oriented script.
 * @copyright	Copyright © 2010-{PROJECTYEAR} Alexey Gordeyev IK. All rights reserved.
 * @license		GNU General Public License v2.0
 * @author		ALEXEY GORDEYEV IK
 * @author mail	admin@gordejev.lv
 * @website		www.gordejev.lv
 *
 * CODE GENERATED BY: ALEXEY GORDEYEV IK CODE GENERATOR
 * HTTP://WWW.AGJOOMLA.COM/
 *
 *
 */

// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );

define('PATH_TO_MOD_CACHE', JURI::base()."modules/".$modulename."/cache/");

/**
 *
 * Easy Reflections Class
 * @since {SINCE}
 *
 */
Class Reflector
{

   /**
    *
    * Required,	The source image (to reflect)
    * @var string
    */
   var $img		= null;

   /**
    *
    * Image details
    * @var array
    */
   var $image_details   = array();

   /**
    *
    * The image body
    * @var string
    */
   var $img_body		= null;

   /**
    *
    * Optional, Height of the reflection (% or pixel value)
    * @var integer
    */
   var $height	        = 0.50;

   /**
    *
    * Optional, Background colour to fade into, default = #000000
    * @var string
    */
   var $bgc		    = '#000000';

   /**
    *
    * Optional, Start the alpha fade from whch value? (% value)
    * @var integer
    */
   var $fade_start  = 80;

   /**
    *
    * Optional, End the alpha fade from whch value? (% value)
    * @var integer
    */
   var $fade_end    = 0;

   /**
    *
    * Optional, Output will be JPEG at 'param' quality (default 80)
    * @var string
    */
   var $jpeg	    = 80;

   /**
    *
    * Optional, Save reflection image to the cache? (boolean)
    * @var unknown_type
    */
   var $cache       = true;

   /**
    *
    * Replace special chars to be HTML-Code
    * @access public
    * @param  string $string
    * @return string
    */
   public static function stringToHTML($string)
   {
      $array_search = array('й', 'и', 'л', 'к', 'а', 'д', 'Д', 'в', 'щ', 'ь', 'Ь', 'ы', 'ц', 'Ц', 'ф', 'п', 'о');
      $array_replace = array('&eacute;', '&egrave;',	'&euml;', '&ecirc;', '&agrave;', '&auml;', '&Auml;', '&acirc;', '&ugrave;', '&uuml;', '&Uuml;', '&ucirc;', '&ouml;', '&Ouml;', '&ocirc;', '&iuml;', '&icirc;');
      $string_return = str_replace($array_search, $array_replace, $string);
      return $string_return;
   }

   /**
    *
    * PHP Version sanity check
    * @access public
    * @return bool
    */
   public static function checkPHPVersion()
   {
      if (version_compare('4.3.2', phpversion()) == 1)
      {
         return false;
      }
      return true;
   }

   /**
    *
    * GD extensions loaded check
    * @access public
    * @return bool
    */
   public static function checkGDLoaded()
   {
      if (extension_loaded('gd') == false && !dl('gd.so'))
      {
         return false;
      }
      return true;
   }

   /**
    *
    * Set output image height
    * @access public
    * @param  mixed $height
    * @return void
    */
   protected function setHeight($height = 0.50)
   {
      //	Have they given us a percentage?
      if (substr($height, -1) == '%') {
         //	Yes, remove the % sign
         $height = (int) substr($height, 0, -1);

         //	Gotta love auto type casting ;)
         if ($height < 10) {
            $height = "0.0$height";
         }
         else {
            $height = "0.$height";
         }
      } else {
         $height = (int) $height;
      }

      $this->height = $height;
   }

   /**
    *
    * Set start the alpha fade
    * @access public
    * @param  mixed $fade_start
    * @return void
    */
   protected function setFadeStart($fade_start) {
      if (strpos($fade_start, '%') !== false)
      {
         $fade_start = str_replace('%', '', $fade_start);
         $fade_start = (int) (127 * $fade_start / 100);
      }
      else
      {
         $fade_start = (int) $fade_start;

         if ($fade_start < 1 || $fade_start > 127)
         {
            $fade_start = 80;
         }
      }
      $this->fade_start = $fade_start;
   }

   /**
    *
    * Set end the alpha fade
    * @access public
    * @param  mixed $fade_end
    * @return void
    */
   protected function setFadeEnd($fade_end) {
      if (strpos($fade_end, '%') !== false)
      {
         $fade_end = str_replace('%', '', $fade_end);
         $fade_end = (int) (127 * $fade_end / 100);
      }
      else
      {
         $fade_end = (int) $fade_end;

         if ($fade_end < 1 || $fade_end > 0)
         {
            $fade_end = 0;
         }
      }
      $this->fade_end = $fade_end;
   }

   /**
    *
    * Get the image source details
    * @access public
    * @param  string $image
    * @return array
    */
   public static function getImageDetails($image = null) {
      $source_image = ($image)?$image:$this->img;
      $this->image_details = getimagesize($source_image);
      return $this->image_details;
   }

   /**
    *
    * Calculate the output height of the output image
    * @access private
    * @return integer
    */
   private function calculateNewHeight($height = 0) {
      if ($height < 1) {
         //	The output height is a percentage
         $new_height = $height * $this->height;
      } else {
         //	The output height is a fixed pixel value
         $new_height = $this->height;
      }
      return $new_height;
   }

   /**
    * 
    * Enter description here ... getReflectionSource
    * @access private
    * @return string
    */
   private function getReflectionSource() {
      switch ($this->image_details[2])
      {
         case 1:
            //	GIF
            $source = imagecreatefromgif($source_image);
            break;
            	
         case 2:
            //	JPG
            $source = imagecreatefromjpeg($source_image);
            break;
            	
         case 3:
            //	PNG
            $source = imagecreatefrompng($source_image);
            break;
            	
         default:
            $source = null;
      }
      return $source;
   }

   public static function getImageSource()
   {
      if($this->img != '') {
         if ($cache)
         {
            $cache_base = basename($this->img);
            $cache_file = 'refl_' .  $cache_base;
            $cache_path = PATH_TO_MOD_CACHE . $cache_file;
            if (file_exists($cache_path))
            {
               $imgbody = "";
            }
            else {

            }
         }
         else
         {

         }
      }
   }

   public static function makeReflection()
   {

   }

}

?>